import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutterchina/common/net_cache.dart';
import 'package:flutterchina/models/index.dart';
import 'package:shared_preferences/shared_preferences.dart';

const _themes = <MaterialColor>[
  Colors.blue,
  Colors.cyan,
  Colors.teal,
  Colors.green,
  Colors.red
];

class Global {
  static SharedPreferences _preferences;
  static Profile profile = Profile();
  static NetCache netCache = NetCache();

  //是否为release
  static bool get isRelease => bool.fromEnvironment("dart.vm.product");

  //初始化配置信息
  static Future init() async {
    _preferences = await SharedPreferences.getInstance();
    var _profile = _preferences.getString("profile");
    if (_profile != null) {
      try {
        profile = Profile.fromJson(jsonDecode(_profile));
      } catch (e) {
        print(e);
      }
    }
    return profile;
  }
}
